import { Controller } from 'egg';

export default class AdminMsgController extends Controller {
    public async getAllMsg() {
        const { ctx, service } = this;
        const page = ctx.params.page ? parseInt(ctx.params.page, 10) : 1;
        const result = await service.admin.msg.getMsgByPage(ctx.user.id, page, 50);
        ctx.helper.success(ctx, result);
    }

    public async readMsg() {
        const { ctx, service } = this;
        ctx.validate({
            msg_id: 'number',
        });
        await service.admin.msg.readMsg(ctx.request.body.msg_id);
        ctx.helper.success(ctx);
    }

    public async deleteMsg() {
        const { ctx, service } = this;
        ctx.validate({
            msg_id: 'number',
        });
        await service.admin.msg.deleteMsg(ctx.request.body.msg_id);
        ctx.helper.success(ctx);
    }
}
